# vPresent is an immersive presentation creation and display application.
# Copyright (C) 2007 by Infiscape Corporation
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import types

import opendocument


class Visitor(object):
   def __init__(self):
      pass

   def visitNode(self, node):
      if isinstance(node, opendocument.PlainText):
         self.visit_PlainText(node)
      else:
         method_name = 'visit_%s' % opendocument.tagToType(node.element.name)
         if hasattr(self, method_name):
            getattr(self, method_name)(node)
         else:
            #print "WARNING: Unhandled node type", node.__class__
            #print "         Override %s to eliminate this warning." % method_name
            self.visitNodeDefault(node)

   def visitNodeDefault(self, node):
      raise NotImplementedError, "All visitors must implement visitNodeDefault."

   def closeContainer(self):
      pass
